package com.wenhai.spring.boot;

import com.wenhai.spring.boot.service.IHelloService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.Set;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ValidatorApplicationMain.class)
public class test {
    @Autowired
    private IHelloService helloService;
    @Test
    public void methodValidator() {
        try {
            helloService.sayHello(1, "wenhai");
        } catch (ConstraintViolationException e) {
            e.printStackTrace();
            Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
            constraintViolations.forEach(item -> System.out.println(item.getMessage()));
        }
    }
}
